/**
 * 
 */
package adnotatio.common.io;

import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.xml.client.Document;
import com.google.gwt.xml.client.XMLParser;

/**
 * This is a simple sub-class of the {@link TextLoader} interpreting loaded
 * resources as XML documents. This method parses the loaded text into into
 * {@link Document} objects and sends them to the corresponding callback.
 * 
 * @author kotelnikov
 */
public class XMLLoader extends TextLoader {

    /**
     * The default constructor.
     * 
     * @param path the path of the text resource to load
     */
    public XMLLoader(String path) {
        super(path);
    }

    /**
     * The default constructor initializing the full URL to the resource to
     * load.
     * 
     * @param path the local path to the resource to load
     * @param post if this flag is <code>true</code> then this loader uses the
     *        POST method to send the information; otherwise the GET method is
     *        used
     */
    public XMLLoader(String path, boolean post) {
        super(path, post);
    }

    /**
     * This method transforms into an XML document ({@link Document} instance)
     * the text loaded from the server and calls the given callback object with
     * this document.
     * 
     * @see adnotatio.common.io.TextLoader#onSuccess(com.google.gwt.user.client.rpc.AsyncCallback,
     *      java.lang.String)
     */
    protected void onSuccess(AsyncCallback callback, String text)
        throws Exception {
        Document doc = XMLParser.parse(text);
        callback.onSuccess(doc);
    }

}